<?php
include "./Lib/DBMySql.inc";
include "./Lib/Common.php";
include "./Entities/bannersObj.php";
include "./DAL/bannersDAL.php";
include "./Entities/pagepositionsObj.php";
include "./DAL/pagepositionsDAL.php";


$mainDB = NewDB(DATABASE_HOST, DATABASE_NAME , DATABASE_USER, DATABASE_PASSWORD);

$advPosName = $s;

$banners = bannersDAL::GetList($mainDB, "pagepositions.name='$advPosName' AND deleteFlag=0 AND DATE(startDate)<=DATE(NOW()) AND DATE(endDate)>=DATE(NOW())", "", "", $errorPage, 
							   	array('bannerpositions', 'pagepositions'),
								array('banners.id=bannerpositions.bannerID', 'bannerpositions.pagePositionID=pagepositions.id'),
								array('id', 'id,name,width,height'));
//print_r($banners);
if ($banners!=null && count($banners)>0)
{
	$aFiles = $aUrls = $aViewUrls = $aClickUrls = $aWidths = $aHeights = $aPopBanners = $aPopWidths = $aPopHeights = $aDelays = array();
	for ($i=0; $i<count($banners); $i++)
	{
		if ($banners[$i]->image!="" && file_exists("./uploadfiles/banner/".$banners[$i]->image))
		{
			?>
			ADV_MM_preloadImages("<?=URL_SITE?>uploadfiles/banner/<?=$banners[$i]->image?>");
			<?
			$aFiles[] = URL_SITE."uploadfiles/banner/".$banners[$i]->image;
			$aUrls[] = $banners[$i]->linkUrl;
			if ($banners[$i]->urlForView==null || $banners[$i]->urlForView=="")
				$banners[$i]->urlForView = URL_SITE . "view.php?bannerID=".$banners[$i]->id."&pagePositionID=".$banners[$i]->otherFields["pagepositions_id"];
			$aViewUrls[] = $banners[$i]->urlForView;
			if (($banners[$i]->urlForClick==null || $banners[$i]->urlForClick=="") && $banners[$i]->linkUrl!="")
				$banners[$i]->urlForClick = URL_SITE . "click.php?bannerID=".$banners[$i]->id."&pagePositionID=".$banners[$i]->otherFields["pagepositions_id"]."&linkUrl=".$banners[$i]->linkUrl;
			$aClickUrls[] = $banners[$i]->urlForClick;
			$aWidths[] = $banners[$i]->otherFields["pagepositions_width"];
			$aHeights[] = $banners[$i]->otherFields["pagepositions_height"];
			if ($banners[$i]->popImage!="" && file_exists("./uploadfiles/banner/".$banners[$i]->popImage)) {
				$aPopBanners[] = URL_SITE."uploadfiles/banner/".$banners[$i]->popImage;
				?>
                ADV_MM_preloadImages("<?=URL_SITE?>uploadfiles/banner/<?=$banners[$i]->popImage?>");
                <?
			}
			else
				$aPopBanners[] = "";
			$aPopWidths[] = $banners[$i]->popWidth;
			$aPopHeights[] = $banners[$i]->popHeight;
			$aDelays[] = $banners[$i]->delayPeriod;
		}
	}
	if (count($banners)==1) $aDelays[0] = 60;
?>
var	bannersS<?=$banners[0]->otherFields["pagepositions_id"]?>	= Array(<?="'".implode("','", $aFiles)."'"?>);
var urlsS<?=$banners[0]->otherFields["pagepositions_id"]?>		= Array(<?="'".implode("','", $aUrls)."'"?>);
var viewurlsS<?=$banners[0]->otherFields["pagepositions_id"]?>	= Array(<?="'".implode("','", $aViewUrls)."'"?>);
var clickurlsS<?=$banners[0]->otherFields["pagepositions_id"]?>	= Array(<?="'".implode("','", $aClickUrls)."'"?>);
var widthsS<?=$banners[0]->otherFields["pagepositions_id"]?>	= Array(<?="'".implode("','", $aWidths)."'"?>);
var heightsS<?=$banners[0]->otherFields["pagepositions_id"]?>	= Array(<?="'".implode("','", $aHeights)."'"?>);
var popbannersS<?=$banners[0]->otherFields["pagepositions_id"]?>= Array(<?="'".implode("','", $aPopBanners)."'"?>);
var popWidthsS<?=$banners[0]->otherFields["pagepositions_id"]?>	= Array(<?="'".implode("','", $aPopWidths)."'"?>);
var popHeightsS<?=$banners[0]->otherFields["pagepositions_id"]?>= Array(<?="'".implode("','", $aPopHeights)."'"?>);
var delaysS<?=$banners[0]->otherFields["pagepositions_id"]?>	= Array(<?="'".implode("','", $aDelays)."'"?>);
document.writeln("<div id='adv<?=$advPosName?>'></div>");
document.writeln("<div id='img<?=$advPosName?>'></div>");
document.writeln("<div id='pop<?=$advPosName?>Count' style='visibility:hidden; position: absolute; border: 0px solid; border-color:#FECC36; padding: 1px; z-index: 100<?=$banners[0]->otherFields["pagepositions_id"]?>; text-align:center; vertical-align:middle;opacity:.7;'></div>");
document.writeln("<div id='pop<?=$advPosName?>' style='visibility:hidden; position: absolute; border: 0px solid; border-color:#FECC36; padding: 1px; z-index: 200<?=$banners[0]->otherFields["pagepositions_id"]?>; text-align:center; vertical-align:middle;opacity:.7;'></div>");
document.writeln("<div id='pop<?=$advPosName?>Close' style='width:10; height:10; visibility:hidden; position: absolute; border: 0px solid; border-color:#FECC36; padding: 1px; z-index: 300<?=$banners[0]->otherFields["pagepositions_id"]?>; text-align:center; vertical-align:middle;opacity:.7;'><a href='javascript: var a=1;'><img src=\"<?=URL_SITE?>images/close.gif\" border=0 onClick=\"closePopupBanner('pop<?=$advPosName?>');\" /></a></div>");
openBanner("<?=URL_SITE?>", "adv<?=$advPosName?>", "pop<?=$advPosName?>", "img<?=$advPosName?>", 0, 
            "bannersS<?=$banners[0]->otherFields["pagepositions_id"]?>", 
            "urlsS<?=$banners[0]->otherFields["pagepositions_id"]?>", 
            "viewurlsS<?=$banners[0]->otherFields["pagepositions_id"]?>", 
            "clickurlsS<?=$banners[0]->otherFields["pagepositions_id"]?>", 
            "widthsS<?=$banners[0]->otherFields["pagepositions_id"]?>", 
            "heightsS<?=$banners[0]->otherFields["pagepositions_id"]?>", 
            "popbannersS<?=$banners[0]->otherFields["pagepositions_id"]?>", 
            "popWidthsS<?=$banners[0]->otherFields["pagepositions_id"]?>", 
            "popHeightsS<?=$banners[0]->otherFields["pagepositions_id"]?>", 
            "delaysS<?=$banners[0]->otherFields["pagepositions_id"]?>");

<?
}
?>
